<?php
//判断是否正当访问
if(!defined('IN_DISCUZ') || empty($_G['uid']) || empty($_G['gp_tid']) || empty($_G['gp_applyid'])) {
	exit('Access Denied');
}

require_once DISCUZ_ROOT.'./source/plugin/donkey_activity/donkey_activity.func.php';
//判断活动状态，访问权限
$activity = get_activity('', 'manager');

//用户分组
$all_group=all_group();

//TODO, check applyid, only security
$query = DB::query('SELECT applyid, username, uid, verified, dateline, message, payment, ufielddata FROM '.DB::table('donkey_activity_apply').' WHERE applyid in ('.$_G['gp_applyid'].') and tid='.$_G['gp_tid'].' ORDER BY dateline DESC');
loadcache('profilesetting');
while($activityapplies = DB::fetch($query)) {

	$activityapplies['user'] = DB::fetch_first('SELECT m.username, mp.realname, m.groupid, mp.gender, mp.telephone, mp.msn, mp.qq, mp.mobile, mp.idcardtype, mp.idcard, mp.bloodtype, mp.zipcode, mp.address FROM '.DB::table('common_member').' m, '.DB::table('common_member_profile').' mp WHERE m.uid='.$activityapplies['uid'].' and mp.uid='.$activityapplies['uid']);

	$activityapplies['user']['groupid'] = $all_group[$activityapplies['user']['groupid']];
	$activityapplies['user']['gender'] = get_gender($activityapplies['user']['gender']);
	$applylist[] = $activityapplies;
}

//判断是否需要打印
if(empty($applylist)){
	showmessage('没有需要打印的会员');
}
$agreement=$_G['cache']['plugin']['donkey_activity']['agreement'];
if(empty($agreement)){
	$agreement = DB::fetch_first('SELECT value FROM '.DB::table('common_pluginvar').' WHERE variable=\'activity_agreement\'');	// and pluginid=\''.$pluginid.'\'
	if(empty($agreement) || empty($agreement['value'])){
		$agreement='没有报名协议';
	} else {
		$agreement=$agreement['value'];
		//$agreement=str_replace($agreement['value'], '\n', '<br/>');
	}
}

include template('donkey_activity:print');

?>